import { testSort, swap } from "./utils";
import { measureSort } from "hy-algokit";

function bubbleSort(arr: number[]): number[] {
  const n = arr.length;
  for (let j = 0; j < n; j++) {
    let swapped = true;
    for (let i = 0; i < n - 1 - j; i++) {
      if (arr[i] > arr[i + 1]) {
        // [arr[i], arr[i + 1]] = [arr[i + 1], arr[i]];
        swap(arr, i, i + 1);
        swapped = true;
      }
    }
    if (!swapped) break;
  }

  return arr;
}

//test代码
testSort(bubbleSort);
measureSort(bubbleSort, 10000);
